<?php # Верхнее меню

class menu_top extends Load_use
{
	function getBlock()
	{
		$html = '';
		global $menu_page_ids;
		global $kvantis;

		
			foreach( $menu_page_ids as $page_id )
				$parents[$page_id] = '"#'.$page_id.'#"';
			$this->conn->query('SELECT `id`, `url`, `title`, `parents` FROM `pages` WHERE `parents` IN( '.implode( ',', $parents ).' ) AND templ = "_simple" or templ = "video_page"');
			while( $row = $this->conn->fetch() )
				$sum_menu[$row->parents][] = array( 'id' => $row->id, 'url' => $row->url, 'title' => $row->title );

			$this->conn->query('SELECT `id`, `url`, `title` FROM `pages` WHERE `id` IN( '.implode( ',', $menu_page_ids ).' ) order by zin');
			while( $row = $this->conn->fetch() )
			{
				$sub_html = $rarget = '';
				if( isset( $sum_menu['#'.$row->id.'#'] ) )
				{
					$sub_html .= '<div class="top-panel__navi__sub-list"><ul>';
					foreach( $sum_menu['#'.$row->id.'#'] as $sub )
					{
						$url = '/'.$row->url.'/'.$sub['url'];
						$rarget_sub = '';
						if( array_key_exists( $sub['id'], $kvantis ) ) {
							$rarget_sub = 'target="_blank"';
							$url = 'http://kvantis.ru'.$kvantis[$sub['id']];
						}
						$sub_html .= '<li'.( ( $this->view->url == $sub['url'] ) ? ' class="selected"' : '' ).'><a '.$rarget_sub.' href="'.$url.'">'.$sub['title'].'</a></li>';
					}
					$sub_html .= '</ul></div>';
				}
				$url = '/'.$row->url;
				if( array_key_exists( $row->id, $kvantis ) ) {
					$rarget = 'target="_blank"';
					$url = 'http://kvantis.ru'.$kvantis[$row->id];
				}
				$html .= '<li'.( ( $row->url == $this->view->url || '/'.$row->url == $this->view->url_before ) ? ' class="selected"' : '' ).'>
						<a '.$rarget.' href="'.$url.'">'.$row->title.'</a>
						'.$sub_html.'
					 </li>';
			}
			$top_navi = '<div class="top-panel centering">
					<div class="top-panel__inner">
						<ul class="top-panel__navi">
							<li>
								<a href="/">
									<span>home</span>
								</a>
							</li>
							'.$html.'
						</ul>
					</div>
				</div>';

			return $top_navi;
		
	}
}